<?php
require_once ('scripts.php');
$action=$_REQUEST['action'];
	if($action=='getSearchSortCriterias')
	{   
		$start=$_POST['searchStart'];
	    $count=$_POST['searchCount'];
		
        $resultArrCol = assetDAOImpl::getInstance()->getAssetByCat($start, $count,10);
        
		$sortStart = $_POST['searchStart'];
		$sortCount=$_POST['sortCount'];
		
		$sortCriteriaResultArrCol = assetDAOImpl::getInstance()->getAssetByCat($start, $count,11);
		   
		$data = array("count"=>$resultArrCol->count, "searchCriterias"=>$resultArrCol->assets, "sortCriterias"=>$sortCriteriaResultArrCol->assets, "sortCount"=>$sortCriteriaResultArrCol->count);
		echo json_encode($data);
	}
	
	if($action=='getSearchCriterias')
	{   
		$start=$_POST['start'];
	    $count=$_POST['count'];
        $resultArrCol = assetDAOImpl::getInstance()->getAssetByCat($start, $count,10);
		   
		$data = array("searchCount"=>$resultArrCol->count, "searchCriterias"=>$resultArrCol->assets);
		echo json_encode($data);
	}
	
	if($action=='getSortCriterias')
	{   
		$start=$_POST['start'];
	    $count=$_POST['count'];
		$resultArrCol =assetDAOImpl::getInstance()->getAssetByCat($start, $count,11);
		   
		$data = array("sortCount"=>$resultArrCol->count, "sortCriterias"=>$resultArrCol->assets);
		echo json_encode($data);
	}
	if($action=='getallassets')
	{   
		$start=0;
		$count=4;
		$drivetrian = assetDAOImpl::getInstance()->getAssetByCat($start, $count,1);
		$engine = assetDAOImpl::getInstance()->getAssetByCat($start, $count,2);
		$transmission = assetDAOImpl::getInstance()->getAssetByCat($start, $count,3);
		$want = assetDAOImpl::getInstance()->getAssetByCat($start, $count,4);
		$contact = assetDAOImpl::getInstance()->getAssetByCat($start, $count,5);
		$paperwork = assetDAOImpl::getInstance()->getAssetByCat($start, $count,6);
		$located = assetDAOImpl::getInstance()->getAssetByCat($start, $count,7);
		$deliver = assetDAOImpl::getInstance()->getAssetByCat($start, $count,8);
		$adsource = assetDAOImpl::getInstance()->getAssetByCat($start, $count,9);
               // $transportation = companyDAOImpl::getInstance()->getTowerCompany();
		   $data = array("driCount"=>$drivetrian->count, "drivetrian"=>$drivetrian->assets,"engineCount"=>$engine->count, "engine"=>$engine->assets,"transmissionCount"=>$transmission->count, "transmission"=>$transmission->assets,"wantCount"=>$want->count, "want"=>$want->assets,"contactCount"=>$contact->count, "contact"=>$contact->assets,"paperCount"=>$paperwork->count, "paperwork"=>$paperwork->assets,"locatedCount"=>$located->count, "located"=>$located->assets,"deliverCount"=>$deliver->count, "deliver"=>$deliver->assets,"adsourceCount"=>$adsource->count, "adsource"=>$adsource->assets);
		echo json_encode($data);
		
		//echo json_encode($data);
	}
	if($action=='getenginecriterias')
	{
		$start=$_POST['start'];
	    $count=$_POST['count'];
		$engine = assetDAOImpl::getInstance()->getAssetByCat($start, $count,2);
		$data = array("engineCount"=>$engine->count, "engine"=>$engine->assets);
		echo json_encode($data);
	}
	if($action=='getdricriterias')
	{
		$start=$_POST['start'];
	    $count=$_POST['count'];
		$drivetrian = assetDAOImpl::getInstance()->getAssetByCat($start, $count,1);
		$data = array("driCount"=>$drivetrian->count, "drivetrian"=>$drivetrian->assets);
		echo json_encode($data);
	}if($action=='getdtrancriterias')
	{
		$start=$_POST['start'];
	    $count=$_POST['count'];
		$transmission = assetDAOImpl::getInstance()->getAssetByCat($start, $count,3);
		$data = array("transmissionCount"=>$transmission->count, "transmission"=>$transmission->assets);
		echo json_encode($data);
	}if($action=='getwantcriterias')
	{
		$start=$_POST['start'];
	    $count=$_POST['count'];
		$want = assetDAOImpl::getInstance()->getAssetByCat($start, $count,4);
		$data = array("wantCount"=>$want->count, "want"=>$want->assets);
		echo json_encode($data);
	}if($action=='getcontactcriterias')
	{
		$start=$_POST['start'];
	    $count=$_POST['count'];
		$contact = assetDAOImpl::getInstance()->getAssetByCat($start, $count,5);
		$data = array("contactCount"=>$contact->count, "contact"=>$contact->assets);
		echo json_encode($data);
	}if($action=='getpapercriterias')
	{
		$start=$_POST['start'];
	    $count=$_POST['count'];
		$paperwork = assetDAOImpl::getInstance()->getAssetByCat($start, $count,6);
		$data = array("paperCount"=>$paperwork->count, "paper"=>$paperwork->assets);
		echo json_encode($data);
	}if($action=='getlocatedcriterias')
	{
		$start=$_POST['start'];
	    $count=$_POST['count'];
		$located = assetDAOImpl::getInstance()->getAssetByCat($start, $count,7);
		$data = array("locatedCount"=>$located->count, "located"=>$located->assets);
		echo json_encode($data);
	}if($action=='getdelivercriterias')
	{
		$start=$_POST['start'];
	    $count=$_POST['count'];
		$deliver = assetDAOImpl::getInstance()->getAssetByCat($start, $count,8);
		$data = array("deliverCount"=>$deliver->count, "deliver"=>$deliver->assets);
		echo json_encode($data);
	}if($action=='getadsourcecriterias')
	{
		$start=$_POST['start'];
	    $count=$_POST['count'];
		$adsource = assetDAOImpl::getInstance()->getAssetByCat($start, $count,9);
		$data = array("adsourceCount"=>$adsource->count, "adsource"=>$adsource->assets);
		echo json_encode($data);
	}
	
	if($action=='addAsset')
	{
	
		$assetVO = new AssetVO();
		$assetVO->assetName = $_POST['asset_name'];
		$assetVO->assetDataField = $_POST['asset_datafield'];
		$assetVO->assetCategory = $_POST['asset_category'];
		$assetVO->createdBy = $_POST['created_by'];
		
		$result = assetDAOImpl::getInstance()->addAsset($assetVO);
		$data = array("result"=>$result);
		echo json_encode($data);
		
	}
	
	if($action=='editAsset')
	{
	
		$assetVO = new AssetVO();
		$assetVO->assetID = $_POST['asset_id'];
		$assetVO->assetName = $_POST['asset_name'];
		$assetVO->assetDataField = $_POST['asset_datafield'];
		$assetVO->updatedBy = $_POST['updated_by'];
		
		$result = assetDAOImpl::getInstance()->editAsset($assetVO);
		$data = array("result"=>$result);
		echo json_encode($data);
		
	}
	
	if($action=='deleteAsset')
	{

		$assetID = $_POST['asset_id'];
		
		$result = assetDAOImpl::getInstance()->deleteAsset($assetID);
		$data = array("result"=>$result);
		echo json_encode($data);
		
	}
        
        if($action=='getCityByState')
        {
            $state_code = $_POST["state_code"]; 
            $cities = assetDAOImpl::getInstance()->getCitiesByState($state_code);
            $data = array("cities"=>$cities);
            echo json_encode($data);
        }
        
        if($action=='getModelByMake')
        {
            $make_id =$_POST["make_id"];
            $models = ModelDAOImpl::getInstance()->getModelByMake($make_id);
              $data = array("models"=>$models);
            echo json_encode($data);
        }
        
        
	if($action=='initialAssets')
	{

		$drivetrian = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,1);
		$engine = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,2);
		$transmission = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,3);
		$want = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,4);
		$contact = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,5);
		$paperwork = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,6);
		$located = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,7);
		$deliver = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,8);
		$adsource = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,9);
		$search = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,10);
		$sort = assetDAOImpl::getInstance()->getAssetByCat(0,0 ,11);
		$transportation = companyDAOImpl::getInstance()->getTowerCompany();
		$states = assetDAOImpl::getInstance()->getStates();
		$makes = MakeDAOImpl::getInstance()->getMakes();
		 $tow = assetDAOImpl::getInstance()->gettow_Status();
                
		   $data = array("tow_status"=>$tow ,"driCount"=>$drivetrian->count, "drivetrian"=>$drivetrian->assets,"engineCount"=>$engine->count, "engine"=>$engine->assets,"transmissionCount"=>$transmission->count, "transmission"=>$transmission->assets,"wantCount"=>$want->count, "want"=>$want->assets,"contactCount"=>$contact->count, "contact"=>$contact->assets,"paperCount"=>$paperwork->count, "paperwork"=>$paperwork->assets,"locatedCount"=>$located->count, "located"=>$located->assets,"deliverCount"=>$deliver->count, "deliver"=>$deliver->assets,"adsourceCount"=>$adsource->count, "adsource"=>$adsource->assets, "search"=>$search->assets, "sort"=>$search->assets,"transportation"=>$transportation, "states"=>$states, "makes"=>$makes );
		echo json_encode($data);
		
	}
        
        
	
?>	